/**
 * jquery 自定义拖拽插件，依赖 MUI
 */
(function ($) {
    $.fn.extend({
        "dragEffect": function (dom) {
            var Y=0,X=0,top;
            var elem = $(this);
            var height = $(window).height(),width = $(window).width();
            var elemWidth=parseInt(elem.css("width")),elemHeight=parseInt(elem.css("height"));
            mui('body').on("dragstart",dom,function (e) {
                Y = elem.offset().top;X = elem.offset().left;
                top=$(window).scrollTop();
                $("body").css({overflow: 'hidden',"position":"fixed","width":"100%","top":top*-1});
            });
            mui('body').on("drag",dom,function (e) {
                var t = (Y + e.detail.deltaY);
                var l = (X + e.detail.deltaX);
                t = t<=0?0:t;
                t = t>($(window).scrollTop()+height-elemHeight)?($(window).scrollTop()+height-elemHeight):t;
                l = l<=0?0:l;
                l = l>(width-elemWidth)?(width-elemWidth):l;
                if(($(window).scrollTop()+height-elemHeight)!==t){
                    elem.css({left:l+'px',top:(t-$(window).scrollTop())+'px'});
                }else{
                    elem.css({left:l+'px'});
                }
            });
            mui('body').on("dragend",dom,function (e) {
                $("body").css({overflow: 'auto',"position":"static"});
                $(window).scrollTop(top);
                setTimeout(function () {
                    if(elem.offset().left<(width-elemWidth)/2){
                        elem.css({left:0,"border-radius":'0 2.5rem 2.5rem 0'});
                    }else{
                        elem.css({left:(width-elemWidth),"border-radius":'2.5rem 0 0 2.5rem'});
                    }
                },1000)
            });
        }
    })
})(jQuery);